﻿using System;
using UnityEngine;
using UnityEngine.UI;

[RequireComponent(typeof(Button))]
public class UIDisableButton : MonoBehaviour
{
    private Button button;
    public GameObject target;

    private void Start()
    {
        this.button = base.GetComponent<Button>();
        this.button.onClick.AddListener(delegate {
            Animator anim = this.target.GetComponent<Animator>();
            if (anim != null)
            {
                if (!anim.IsStatePlaying("Disable"))
                {
                    this.StartPlayAnimationAndWaitForEnd(anim, "Disable", () => this.target.SetActive(false));
                }
            }
            else
            {
                this.target.SetActive(false);
            }
        });
    }
}

